
#include "qyZipEntry.h"

//-----------------------------------------------------------------------
qyZipEntry::qyZipEntry()
{

}

//-----------------------------------------------------------------------
qyZipEntry::~qyZipEntry()
{
	int numSubEntries = (int)m_children.size();
	for ( int i = 0; i < numSubEntries; i++ )
	{
		qyZipEntry *sub = m_children[i];
		delete sub;
	}
}

//-----------------------------------------------------------------------
void qyZipEntry::Setup( const qyString &entryPath, const qyString &token )
{
	m_pathInZip = entryPath;
	m_isDirectory = ( m_pathInZip[strlen( m_pathInZip.c_str() ) - 1 ] == '/' );
	m_token = token;
}

//-----------------------------------------------------------------------
qyZipEntry *qyZipEntry::AddSubEntry( const qyString &path, const qyString &subentry )
{
	qyZipEntry *entry = new qyZipEntry();
	entry->Setup( path, subentry );
	m_children.push_back( entry );
	return entry;
}

//-----------------------------------------------------------------------
int qyZipEntry::NumSubEntry() const
{
	return (int)m_children.size();
}

//-----------------------------------------------------------------------
qyZipEntry * qyZipEntry::GetSubEntryAt( const int index )
{
	if ( index >= 0 && index < (int)m_children.size() )
	{
		return m_children[index];
	}
	return NULL;
}

//-----------------------------------------------------------------------
qyZipEntry * qyZipEntry::FindDirEntry( const qyString &path )
{
	int numSubEntries = (int)m_children.size();
	for ( int i = 0; i < numSubEntries; i++ )
	{
		qyZipEntry *entry = m_children[i];
		if ( entry->GetToken() == path )
		{
			return entry;
		}
	}
	return NULL;
}
